define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'base/source/index',
                    add_url: 'base/source/add',
                    edit_url: 'base/source/edit',
                    del_url: 'base/source/del',
                    multi_url: 'base/source/multi',
                    table: 'base_source',
                   import_url: 'base/source/import',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'url', title: __('链接'), align: 'left', formatter: Controller.api.formatter.url},
                        {field: 'erweima_url', title: __('二维码'), formatter: Controller.api.formatter.avatar},
                        {field: 'poster_url', title: __('海报图片'), formatter: Controller.api.formatter.avatar},
                        // {field: 'delete_status', title: __('Delete_status')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'publish_text', title: __('Publish'), operate:false },
                        // {field: 'z_publish', title: __('Z_publish')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
          formatter: {//渲染的方法
             url: function (value, row, index) {
                    return '<div class="input-group input-group-sm" style="width:250px;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
                },
            avatar: function (value, row, index) {
              return '<a href="'+value+'" target="_blank" download="'+row['name']+'.png" ><img width="45" height="45" src="'+value+'" ></a>';
            },
          
          }
        }
    };
    return Controller;
});